'use strict';

module.exports = app => {
    class LikeService extends app.Service {
        constructor(ctx) {
            super(ctx);
        }

        //点赞
        async clicklike(params) {
            const result = await this.ctx.fetch(this.app.urls('clicklike'), {
                method: 'post',
                data: {
                    type:params.type,
                    domainId:params.domainId,
                },
                dataType: 'json',
            });
            let data = result.data;

            this.app.logger.info(data);

            if (data.code != 200){
                throw new Error(data.message ? data.message : 'error');
            }

            return data;
        }

        //取消点赞
        async noclicklike(params) {
            const result = await this.ctx.fetch(this.app.urls('noclicklike'), {
                method: 'post',
                data: {
                    likeId:params.likeId,
                },
                dataType: 'json',
            });
            let data = result.data;

            this.app.logger.info(data);
            console.log(data)
            if (data.code != 200){
                throw new Error(data.message ? data.message : 'error');
            }

            return data.data;
        }

    }

    return LikeService;
};
